package com.example.team.rest.common.datasources.dynamic;

import com.example.team.rest.common.datasources.DataSourceContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;

/**
 * 获取数据源
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
    private static final Logger LOG = LoggerFactory.getLogger(DynamicDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        LOG.debug("数据源为{}", DataSourceContextHolder.getDatasource());
        return DataSourceContextHolder.getDatasource();
    }

}
